class Admin::ActivitiesController < AdminController
  def index
    @activities = Activity.order("created_at DESC").page(params[:page]).per(params[:per])
  end

  def new
    @activity = Activity.new
  end

  def create
    @activity = Activity.new activity_params
    if @activity.save
      redirect_to admin_activities_path, notice: "保存成功！"
    else
      redirect_to admin_activities_path, notice: "保存失败！"
    end
  end

  def edit
    @activity = Activity.find params[:id]
  end

  def update
    @activity = Activity.find params[:id]
    if @activity.update activity_params
      redirect_to admin_activities_path, notice: "更新成功！"
    else
      redirect_to admin_activities_path, notice: "更新失败！"
    end
  end
  
  def destroy
    @activity = Activity.find params[:id]
    if @activity.destroy
      redirect_to admin_activities_path, notice: "删除成功."
    else
      redirect_to admin_activities_path, notice: "删除失败."
    end
  end

  private

  def activity_params
    params.require(:activity).permit(:name, :state)
  end
end
